package com.cl.edu.web;

import java.util.List;
import java.util.Random;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;

import com.cl.common.CrudActionSupport;
import com.cl.core.orm.Page;
import com.cl.edu.entity.Area;
import com.cl.edu.entity.Bookingstudent;
import com.cl.edu.entity.Bookingteacher;
import com.cl.edu.entity.Highschool;
import com.cl.edu.entity.News;
import com.cl.edu.entity.Newssort;
import com.cl.edu.entity.Status;
import com.cl.edu.entity.Student;
import com.cl.edu.entity.Subject;
import com.cl.edu.entity.Teacher;
import com.cl.edu.service.IndexManager;
import com.cl.edu.service.RegisterManager;
import com.cl.edu.service.TeacherQueryManager;
import com.cl.edu.service.admin.NewsManager;
/**
 * 相关教师查询ACTION
 * @author Administrator
 *
 */
@Results( { @Result(name = "techerinfo", location = "teacher_info.jsp") })
public class TeacherAction extends CrudActionSupport<Teacher> {
	
	private static final long serialVersionUID = 5570012221779895112L;
	@Autowired
	private TeacherQueryManager teacherQueryManager;
	@Autowired
	private NewsManager newsManager;
	@Autowired
	private IndexManager indexManager;
	@Autowired
	private RegisterManager registerManager;
	private Long id;
	private Teacher entity;
	private Page<Teacher> page=new Page<Teacher>();
	
	private List<Bookingteacher> bookSuccess;//查询教员信息时   查询该教员预约成功的信息  学员主动预约
	private List<Bookingstudent> bookSuccess1;//查询教员信息时 查询该教员预约成功的信息 教员主动预约
	private List<Area>  syList;//沈阳区划
	private List<Subject> subjectList;//教师任教学科列表
	private List<Status> statusList;//身份列表
	private List<Highschool> hxList;//高校列表
	//新闻模块
	private Page<News> newsPage = new Page<News>();	//内容列表
	private List<Newssort> newssortList;
	private List<News> list	  ;					//栏目列表
	private List<News> list1  ;					//右边栏列表1
	private List<News> list2  ;					//右边栏列表2
	private List<News> list3  ;					//右边栏列表3
	private List<News> list4  ;					//右边栏列表4
	
	//查询条件定义
	private String filter_subject;//科目 多个之间以,进行分割
	private String filter_areaid;//地区
	private String filter_status;//身份
	private String filter_sex;//性别
	private String filter_hx;//高校
	private Long   filter_step;//用户等级 0为普通 -1代表不为0的星级用户
	private Long   filter_statusType;//身份类型  0代表所有 1代表学生 2代表教师 3代表老外
	private String filter_fi;//按照subject的ID范围查找 格式为"2-200;210-230"
	public String execute() throws Exception {
		if (!page.isOrderBySetted())		{
			page.setOrderBy("id");
			page.setOrder(Page.DESC);
		}
		page=teacherQueryManager.getChoiceList(page,filter_statusType);
		this.initRight();
		hxList        = registerManager.getHighschools();
		syList        = registerManager.getShenYang();
		statusList   = registerManager.getStatus(filter_statusType);
		subjectList   = registerManager.getSubjects("2");
		return SUCCESS;
	}
	public String queryByIds() throws Exception {
		if (!page.isOrderBySetted())		{
			page.setOrderBy("id");
			page.setOrder(Page.DESC);
		}
		page=teacherQueryManager.getChoiceListByIds(page);
		this.initRight();
		hxList        = registerManager.getHighschools();
		syList        = registerManager.getShenYang();
		statusList   = registerManager.getStatus(filter_statusType);
		subjectList   = registerManager.getSubjects("2");
		return SUCCESS;
	}
	public String queryOne() throws Exception {
		this.prepareModel();
		//查询预约教员成功信息  学员主动
		Page<Bookingteacher> pageb=new Page<Bookingteacher>();
		pageb.setPageSize(15);
		bookSuccess=teacherQueryManager.getBookingTeacherSuccess(pageb, id).getResult();
		//查询预约教员成功信息  教员主动
		Page<Bookingstudent> pages=new Page<Bookingstudent>();
		pages.setPageSize(15);
		bookSuccess1=teacherQueryManager.getBookingStudentSuccess(pages, id).getResult();
		this.initRight();
		return "techerinfo";
	}
	@Override
	public String input() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	//公用右边栏信息
	private void initRight() {
		if (!newsPage.isOrderBySetted())		{
			newsPage.setOrderBy("id");
			newsPage.setOrder(Page.DESC);
		}
		newsPage = indexManager.getNewsById(newsPage, 1L, 6);
		list1 = newsPage.getResult();
		
		newsPage = indexManager.getNewsById(newsPage, 13L, 6);
		list2 = newsPage.getResult();
		
		newssortList = newsManager.getNewssorts();
	}
	@Override
	public String list() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	protected void prepareModel() throws Exception {
		if (id == null) {
			entity = new Teacher();
		} else {
			entity=teacherQueryManager.getTeacherById(id);
		}
	}

	@Override
	public String save() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public String delete() throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
	public Teacher getModel() {
		return entity;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}
	public Teacher getEntity() {
		return entity;
	}
	public void setEntity(Teacher entity) {
		this.entity = entity;
	}

	public List<Newssort> getNewssortList() {
		return newssortList;
	}

	public void setNewssortList(List<Newssort> newssortList) {
		this.newssortList = newssortList;
	}

	public List<News> getList() {
		return list;
	}

	public void setList(List<News> list) {
		this.list = list;
	}

	public List<News> getList1() {
		return list1;
	}

	public void setList1(List<News> list1) {
		this.list1 = list1;
	}

	public List<News> getList2() {
		return list2;
	}

	public void setList2(List<News> list2) {
		this.list2 = list2;
	}

	public List<News> getList3() {
		return list3;
	}

	public void setList3(List<News> list3) {
		this.list3 = list3;
	}

	public List<News> getList4() {
		return list4;
	}

	public void setList4(List<News> list4) {
		this.list4 = list4;
	}
	public void setPage(Page<Teacher> page) {
		this.page = page;
	}
	public Page<Teacher> getPage() {
		return page;
	}
	public List<Area> getSyList() {
		return syList;
	}
	public void setSyList(List<Area> syList) {
		this.syList = syList;
	}
	public List<Subject> getSubjectList() {
		return subjectList;
	}
	public void setSubjectList(List<Subject> subjectList) {
		this.subjectList = subjectList;
	}
	public List<Status> getStatusList() {
		return statusList;
	}
	public void setStatusList(List<Status> statusList) {
		this.statusList = statusList;
	}
	public List<Highschool> getHxList() {
		return hxList;
	}
	public void setHxList(List<Highschool> hxList) {
		this.hxList = hxList;
	}
	public String getFilter_subject() {
		if("".equals(filter_subject)){
			filter_subject="请选择家教科目";
		}
		return filter_subject;
	}
	public void setFilter_subject(String filter_subject) {
		this.filter_subject = filter_subject;
	}
	public String getFilter_areaid() {
		return filter_areaid;
	}
	public void setFilter_areaid(String filter_areaid) {
		this.filter_areaid = filter_areaid;
	}
	public String getFilter_status() {
		if("".equals(filter_status)){
			filter_status="请选择身份信息";
		}
		return filter_status;
	}
	public void setFilter_status(String filter_status) {
		this.filter_status = filter_status;
	}
	public String getFilter_sex() {
		return filter_sex;
	}
	public void setFilter_sex(String filter_sex) {
		this.filter_sex = filter_sex;
	}
	public String getFilter_hx() {
		return filter_hx;
	}
	public void setFilter_hx(String filter_hx) {
		this.filter_hx = filter_hx;
	}
	public Long getFilter_statusType() {
		return filter_statusType;
	}
	public void setFilter_statusType(Long filter_statusType) {
		this.filter_statusType = filter_statusType;
	}
	public void setFilter_step(Long filter_step) {
		this.filter_step = filter_step;
	}
	public Long getFilter_step() {
		return filter_step;
	}
	public void setBookSuccess(List<Bookingteacher> bookSuccess) {
		this.bookSuccess = bookSuccess;
	}
	public List<Bookingteacher> getBookSuccess() {
		return bookSuccess;
	}
	public void setBookSuccess1(List<Bookingstudent> bookSuccess1) {
		this.bookSuccess1 = bookSuccess1;
	}
	public List<Bookingstudent> getBookSuccess1() {
		return bookSuccess1;
	}
	public void setFilter_fi(String filter_fi) {
		this.filter_fi = filter_fi;
	}
	public String getFilter_fi() {
		return filter_fi;
	}
}
